package com.flowable.modules.modeler.behavior;

import org.flowable.bpmn.model.UserTask;
import org.flowable.common.engine.impl.el.ExpressionManager;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
import org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity;
import org.flowable.task.service.TaskService;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

import java.util.List;
import java.util.Map;

/**
 * @Author: qianfang
 * @Date: 2021/1/11 10:02
 */
public class ExtUserTaskActivityBehavior extends UserTaskActivityBehavior {

    public ExtUserTaskActivityBehavior(UserTask userTask) {
        super(userTask);
    }

    @Override
    public void execute(DelegateExecution execution) {
//        System.out.println("这是自定义Behavior的输出：进入节点" + execution.getCurrentActivityId());
        super.execute(execution);
    }

    @Override
    public void trigger(DelegateExecution execution, String signalName, Object signalData) {
//        System.out.println("这是自定义Behavior的输出：触发离开节点" + execution.getCurrentActivityId());
        super.trigger(execution, signalName, signalData);
    }

    @Override
    protected void handleAssignments(TaskService taskService, String assignee, String owner, List<String> candidateUsers, List<String> candidateGroups, TaskEntity task, ExpressionManager expressionManager, DelegateExecution execution) {

//        if (null != this.userTaskExtension) {
//            //由扩展属性读取办理人规则
//            List<DealerInfo> dealerInfos = getDealerInfo();
//            if (null == dealerInfos || dealerInfos.size() == 0) {
//                throw new RuntimeException("处理者信息不存在");
//            }
//            if (hasMultiInstanceCharacteristics()){
//
//                    //多实例节点分配处理者
//                    //获得传参，流程图中的Element Var
//                    Object objDealer = execution.getVariable("dealerInfo");
//                if (objDealer instanceof DealUserInfo) {
//                    DealUserInfo userInfo = (DealUserInfo) objDealer;
//                    assignee = userInfo.getId();
//                } else if (objDealer instanceof DealRoleInfo) {
//                    DealRoleInfo roleInfo = (DealRoleInfo) objDealer;
//                    task.addGroupIdentityLink(roleInfo.getId(), "role");
//                }
//            }
//
//        }


        super.handleAssignments(taskService, assignee, owner, candidateUsers, candidateGroups, task, expressionManager, execution);
    }
}
